Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIR Pass] Decouple flatten buffer to lower opaque block and flatten buffer. #12172

Merged
merged 1 commit into from
Jul 27, 2022

Conversation

FredJia-intellif
Copy link
Contributor

@FredJia-intellif FredJia-intellif commented Jul 25, 2022

This PR intends to decouple flatten buffer pass to lower opaque block and flatten buffer passes. Test cases have been added.

Reasons for the change:

  • Lower opaque block and flatten buffer pass names can express clearly what they do.

  • It's more simply to analyze the buffer shape before flatten buffer with multi-dimension.

@Hzfengsy
Copy link
Member

Will review it tomorrow. also cc @spectrometerHBH @Lunderberg

Copy link
Member

@Hzfengsy Hzfengsy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall lgtm

@FredJia-intellif FredJia-intellif force-pushed the dev_flatten_buffer branch 3 times, most recently from f9c7263 to afbc5a8 Compare July 26, 2022 15:28
@Hzfengsy Hzfengsy merged commit 5711c35 into apache:main Jul 27, 2022
Lunderberg added a commit to Lunderberg/tvm that referenced this pull request Aug 30, 2022
For buffers with more than one physical axis, the `axis_separators`
are required in order to know which groups of logical axes to fuse
into each physical axis.  The implementation in `tir.FlattenBuffer`
assumed that all buffers were being flattened to a single physical
axis.  Because `tir.LowerOpaqueBlock` replaces the
`BlockNode::alloc_buffers` with `Allocate` nodes, `tir.FlattenBuffer`
no longer has access to the axis separators and performs inconsistent
flattening for `Allocate` as opposed to `BufferLoad`/`BufferStore`.
This was introduced in apache#12172, which
decoupled the lowering/flattening steps.

The commit reorders the `tir.FlattenBuffer` to occur before
`tir.LowerOpaqueBlock`, to make use of the axis separators.  Any
`Allocate` nodes that exist at that point (e.g. from hand-written
schedules) are still flattened to 1-d physical buffers, but the
`BlockNode::alloc_buffers` are flattened according to the axis
separators.
wrongtest-intellif pushed a commit that referenced this pull request Sep 8, 2022
* [TIR] Moved tir.FlattenBuffer to occur before tir.LowerOpaqueBlock

For buffers with more than one physical axis, the `axis_separators`
are required in order to know which groups of logical axes to fuse
into each physical axis.  The implementation in `tir.FlattenBuffer`
assumed that all buffers were being flattened to a single physical
axis.  Because `tir.LowerOpaqueBlock` replaces the
`BlockNode::alloc_buffers` with `Allocate` nodes, `tir.FlattenBuffer`
no longer has access to the axis separators and performs inconsistent
flattening for `Allocate` as opposed to `BufferLoad`/`BufferStore`.
This was introduced in #12172, which
decoupled the lowering/flattening steps.

The commit reorders the `tir.FlattenBuffer` to occur before
`tir.LowerOpaqueBlock`, to make use of the axis separators.  Any
`Allocate` nodes that exist at that point (e.g. from hand-written
schedules) are still flattened to 1-d physical buffers, but the
`BlockNode::alloc_buffers` are flattened according to the axis
separators.

* Add unit test to validate non-flat memory after tvm.lower

* Explicitly write T.reads for test on BufferRegion updates

* Update incorrect docstring for test

* Use DeclBuffer information in FlattenBuffer

The DeclBuffer node can be inserted during LowerOpaqueBlock, then
provide the missing Buffer information required to flatten the
allocation.

* Use T.allocate in unit tests

With the insertion of `DeclBuffer` nodes, `LowerOpaqueBlock` no longer
needs to be before `FlattenBuffer`, and has been moved back to its
original position.  Revering the tests to use `T.allocate` instead of
`T.alloc_buffer` more closely represents the functions as they are
being lowered.

* Fix usage of T.decl_buffer in updated tests

* Update LowerOpaqueBuffer to expect the DeclBuffer nodes

* Strip DeclBuffer annotation in FlattenBuffer

The DeclBuffer annotations aren't yet supported in all passes.  This
restricts them to being introduced in LowerOpaqueBuffer, then
immediately removed in FlattenBuffer.

* Strip out all DeclBuffer nodes in FlattenBuffer

* Update unit tests to remove expectation of DeclBuffer nodes
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
xinetzone pushed a commit to daobook/tvm that referenced this pull request Nov 25, 2022
* [TIR] Moved tir.FlattenBuffer to occur before tir.LowerOpaqueBlock

For buffers with more than one physical axis, the `axis_separators`
are required in order to know which groups of logical axes to fuse
into each physical axis.  The implementation in `tir.FlattenBuffer`
assumed that all buffers were being flattened to a single physical
axis.  Because `tir.LowerOpaqueBlock` replaces the
`BlockNode::alloc_buffers` with `Allocate` nodes, `tir.FlattenBuffer`
no longer has access to the axis separators and performs inconsistent
flattening for `Allocate` as opposed to `BufferLoad`/`BufferStore`.
This was introduced in apache#12172, which
decoupled the lowering/flattening steps.

The commit reorders the `tir.FlattenBuffer` to occur before
`tir.LowerOpaqueBlock`, to make use of the axis separators.  Any
`Allocate` nodes that exist at that point (e.g. from hand-written
schedules) are still flattened to 1-d physical buffers, but the
`BlockNode::alloc_buffers` are flattened according to the axis
separators.

* Add unit test to validate non-flat memory after tvm.lower

* Explicitly write T.reads for test on BufferRegion updates

* Update incorrect docstring for test

* Use DeclBuffer information in FlattenBuffer

The DeclBuffer node can be inserted during LowerOpaqueBlock, then
provide the missing Buffer information required to flatten the
allocation.

* Use T.allocate in unit tests

With the insertion of `DeclBuffer` nodes, `LowerOpaqueBlock` no longer
needs to be before `FlattenBuffer`, and has been moved back to its
original position.  Revering the tests to use `T.allocate` instead of
`T.alloc_buffer` more closely represents the functions as they are
being lowered.

* Fix usage of T.decl_buffer in updated tests

* Update LowerOpaqueBuffer to expect the DeclBuffer nodes

* Strip DeclBuffer annotation in FlattenBuffer

The DeclBuffer annotations aren't yet supported in all passes.  This
restricts them to being introduced in LowerOpaqueBuffer, then
immediately removed in FlattenBuffer.

* Strip out all DeclBuffer nodes in FlattenBuffer

* Update unit tests to remove expectation of DeclBuffer nodes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants